package com.linx.notice.controller;

import java.util.List;

import com.linx.notice.domain.vo.UserVo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.notice.domain.vo.InfoScopeVo;
import com.linx.notice.domain.bo.InfoScopeBo;
import com.linx.notice.service.IInfoScopeService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 信息发布—发送范围管理
 *
 * @author 泽智科技
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/notice/scope")
public class InfoScopeController extends BaseController {

    private final IInfoScopeService infoScopeService;

    /**
     * 查询信息发布—发送范围管理列表
     */
    @SaCheckPermission("notice:scope:list")
    @GetMapping("/list")
    public TableDataInfo<InfoScopeVo> list(InfoScopeBo bo, PageQuery pageQuery) {
        return infoScopeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出信息发布—发送范围管理列表
     */
    @SaCheckPermission("notice:scope:export")
    @Log(title = "信息发布—发送范围管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InfoScopeBo bo, HttpServletResponse response) {
        List<InfoScopeVo> list = infoScopeService.queryList(bo);
        ExcelUtil.exportExcel(list, "信息发布—发送范围管理", InfoScopeVo.class, response);
    }

    /**
     * 获取信息发布—发送范围管理详细信息
     *
     * @param infoScopeId 主键
     */
    @SaCheckPermission("notice:scope:query")
    @GetMapping("/{infoScopeId}")
    public R<InfoScopeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long infoScopeId) {
        return R.ok(infoScopeService.queryById(infoScopeId));
    }

    /**
     * 新增信息发布—发送范围管理
     */
    @SaCheckPermission("notice:scope:add")
    @Log(title = "信息发布—发送范围管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody InfoScopeBo bo) {
        return toAjax(infoScopeService.insertByBo(bo));
    }

    /**
     * 修改信息发布—发送范围管理
     */
    @SaCheckPermission("notice:scope:edit")
    @Log(title = "信息发布—发送范围管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody InfoScopeBo bo) {
        return toAjax(infoScopeService.updateByBo(bo));
    }

    /**
     * 删除信息发布—发送范围管理
     *
     * @param infoScopeIds 主键串
     */
    @SaCheckPermission("notice:scope:remove")
    @Log(title = "信息发布—发送范围管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoScopeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] infoScopeIds) {
        return toAjax(infoScopeService.deleteWithValidByIds(List.of(infoScopeIds), true));
    }

    @GetMapping("/getUserList")
    public R<List<UserVo>> getUserList() {
        return infoScopeService.getUserList();
    }
}
